package com.gpframework.module.purchase.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.utils.DateUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.purchase.domain.GpPurchaseReceipt;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @ClassName GpPurchaseReceiptReq
 * @Author gpframework
 * @Date 2023-12-22
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpPurchaseReceiptReq extends BaseReq {
    private static final long serialVersionUID = 1L;

         @ApiModelProperty("品牌id")
     private String brandId;
     @ApiModelProperty("品牌名称")
     private String brandName;
     @ApiModelProperty("缺货报库存申请表id")
     private Long productionApplicationId;
     @ApiModelProperty("做货明细表id")
     private Long purchasingDetailsId;
     @ApiModelProperty("排单表id")
     private Long procureSchedulingId;
     @ApiModelProperty("收货单号")
     private String sn;
     @ApiModelProperty("批号")
     private String batchNo;
     @ApiModelProperty("发货日期")
     private Date sendTime;
     @ApiModelProperty("物流")
     private String logistics;
     @ApiModelProperty("供应商")
     private String supplier;
     @ApiModelProperty("染厂名称")
     private String dyeWorksName;
     @ApiModelProperty("品名")
     private String productName;
     @ApiModelProperty("颜色")
     private String productColor;
     @ApiModelProperty("条数")
     private Integer quantity;
     @ApiModelProperty("规格")
     private String norms;
     @ApiModelProperty("总码数")
     private String totalSize;
     @ApiModelProperty("大小条（码）")
     private Integer sizeBar;
     @ApiModelProperty("包数")
     private Integer packNum;
     @ApiModelProperty("总包数")
     private Integer totalPackNum;
     @ApiModelProperty("实际到货条数")
     private Integer actualArrivalQuantity;
     @ApiModelProperty("备注")
     private String remarks;
     @ApiModelProperty("货架号")
     private String goodsNum;
     @ApiModelProperty("操作人id")
     private Long merchandiserId;
     @ApiModelProperty("操作人")
     private String merchandiser;
     @ApiModelProperty("操作时间")
     private Date operatorTime;
     @ApiModelProperty("订单二维码")
     private String orderQrCode;
     @ApiModelProperty("关联订单号")
     private String relatedOrderNumber;
    @ApiModelProperty("查询条件（订单号/客户名）")
    private String searchName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date searchDate;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpPurchaseReceipt> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
            lqw.orderByDesc(alias + "create_time");
        }
        if (StringUtils.isNotBlank(this.getBrandId())){
        lqw.eq(alias+"brand_id" ,this.getBrandId());
        }
        if (StringUtils.isNotBlank(this.getBrandName())){
            lqw.like(alias+"brand_name",this.getBrandName());
        }
        if (this.getProductionApplicationId() != null){
        lqw.eq(alias+"production_application_id" ,this.getProductionApplicationId());
        }
        if (this.getPurchasingDetailsId() != null){
        lqw.eq(alias+"purchasing_details_id" ,this.getPurchasingDetailsId());
        }
        if (this.getProcureSchedulingId() != null){
        lqw.eq(alias+"procure_scheduling_id" ,this.getProcureSchedulingId());
        }
        if (StringUtils.isNotBlank(this.getSn())){
        lqw.like(alias+"sn" ,this.getSn());
        }
        if (StringUtils.isNotBlank(this.getBatchNo())){
        lqw.like(alias+"batch_no" ,this.getBatchNo());
        }
        if (this.getSendTime() != null){
        lqw.eq(alias+"send_time" ,this.getSendTime());
        }
        if (StringUtils.isNotBlank(this.getLogistics())){
        lqw.eq(alias+"logistics" ,this.getLogistics());
        }
        if (StringUtils.isNotBlank(this.getSupplier())){
        lqw.like(alias+"supplier" ,this.getSupplier());
        }
        if (StringUtils.isNotBlank(this.getDyeWorksName())){
            lqw.like(alias+"dye_works_name",this.getDyeWorksName());
        }
        if (StringUtils.isNotBlank(this.getProductName())){
            lqw.like(alias+"product_name",this.getProductName());
        }
        if (StringUtils.isNotBlank(this.getProductColor())){
        lqw.like(alias+"product_color" ,this.getProductColor());
        }
        if (this.getQuantity() != null){
        lqw.eq(alias+"quantity" ,this.getQuantity());
        }
        if (StringUtils.isNotBlank(this.getNorms())){
        lqw.eq(alias+"norms" ,this.getNorms());
        }
        if (StringUtils.isNotBlank(this.getTotalSize())){
        lqw.eq(alias+"total_size" ,this.getTotalSize());
        }
        if (this.getSizeBar() != null){
        lqw.eq(alias+"size_bar" ,this.getSizeBar());
        }
        if (this.getPackNum() != null){
        lqw.eq(alias+"pack_num" ,this.getPackNum());
        }
        if (this.getTotalPackNum() != null){
        lqw.eq(alias+"total_pack_num" ,this.getTotalPackNum());
        }
        if (this.getActualArrivalQuantity() != null){
        lqw.eq(alias+"actual_arrival_quantity" ,this.getActualArrivalQuantity());
        }
        if (StringUtils.isNotBlank(this.getRemarks())){
        lqw.eq(alias+"remarks" ,this.getRemarks());
        }
        if (StringUtils.isNotBlank(this.getGoodsNum())){
        lqw.eq(alias+"goods_num" ,this.getGoodsNum());
        }
        if (this.getMerchandiserId() != null){
        lqw.eq(alias+"merchandiser_id" ,this.getMerchandiserId());
        }
        if (StringUtils.isNotBlank(this.getMerchandiser())){
        lqw.like(alias+"merchandiser" ,this.getMerchandiser());
        }
        if (this.getOperatorTime() != null){
        lqw.eq(alias+"operator_time" ,this.getOperatorTime());
        }
        if (StringUtils.isNotBlank(this.getOrderQrCode())){
        lqw.eq(alias+"order_qr_code" ,this.getOrderQrCode());
        }
        if (StringUtils.isNotBlank(this.getRelatedOrderNumber())){
        lqw.eq(alias+"related_order_number" ,this.getRelatedOrderNumber());
        }
        if (StringUtils.isNotBlank(this.getSearchName())) {
            lqw.and(wrapper -> wrapper.like("gp.sn", this.getSearchName()).or().like("gp.product_name", this.getSearchName()).or().like("gp.product_color", this.getSearchName()));
        }
        if (this.getSearchDate() != null) {
            lqw.apply("DATE_FORMAT(gp.create_time, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getSearchDate()) + "'");
        }
    }
}
